A class to serialize complex class structures to XML with almost no coding needed.
For a class to be serialisable then it must have default constructor with no parameters.
Object
XmlSerializer
class XmlSerializer
Properties
ThrowIfMissingProperty | Set this property to true if you want to throw exceptions on missing properties when deserializing. |
Methods
shared DeSerialize | De-serialises a class structure |
shared DeSerialize | De-serialises a class structure, adding also Array of known classes to support de-serializing polymorphic structures. |
shared Serialize | Serialises a class structure |
Constants
Version = 2.0 | |
Examples
You can fine tune your serialized data with the following attributes:SerializeIgnoreTells the serialiser to ignore this property.
Example Usage in the Attribute editor in Xojo:
SerializeIgnoreSerializeRenameTells the serialiser to rename the property in the serialised data. for example if the Xojo property is called Y then you could serialize it as YCoord.
Example Usage in the Attribute editor in Xojo:
SerializeRename "YCoord”SerializeArrayElementName Defines a element name in the XML for array elements for the given property if this Attribute is not used then the element name will be Value.
Example Usage in the Attribute editor in Xojo:
SerializeArrayElementName "Employee”SerializeArrayElementName Defines a element name in the XML for array elements for the given property if this Attribute is not used then the element name will be Value.
Example Usage in the Attribute editor in Xojo:
SerializeArrayElementName "Employee"SerializeArrayElementFactoryTells the de-serialiser to use a custom class factory when constructing instances of class elements in object arrays.
(Note this attribute does nothing on non object arrays, for example it will be ignored on Integer array)
Example Usage in the Attribute editor in Xojo:
SerializeArrayElementFactory “MyCustomClassFactory" This will make the the method called MyCustomClassFactory get called for each element of the array when the array is deserialised.
Signature of the factory method must be
YourMethodName(className as String) as YourClassType where YourMethodName can be any name but must be same as you define in the attribute, and YourClassType is type of the class that you have in the array property.
SerializeOrderDefines the order of the serialisation for the given property.
Example Usage in the Attribute editor in Xojo:
SerializeOrder 2SerializeRequiredAttribute that can optionally be put on class properties. If class property has this and the property is missing when deserialising then exception is thrown regardless of value of the ThrowIfMissingProperty.
Example Usage in the Attribute editor in Xojo:
SerializeRequiredSerializeClassInfo Attribute that can optionally be put on object type class properties. If it is set then the property will include extra class info in the serialised data to support polymorphism. (If for example the Property is Node as Object then with extra class info enabled the class value put in it can still work even if its of type of Subclass of the object).
Example Usage in the Attribute editor in Xojo:
SerializeClassInfo
Supported Platforms:
macOS Intel 64 bitmacOS Apple SiliconWindows 32 bitWindows 64 bitWindows ARM 64 bitLinux 32 bitLinux 64 bitLinux ARM 32 bitLinux ARM 64 bitiOS